package com.atwisdom.star.service.util;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.core.dao.pojo.modelClass.routing.RoutingInstance;
import com.atwisdom.star.core.dsl.modelClass.routing.Impl.RoutingInstanceDslServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
public class RoutingUtil {
    @Autowired
    private RoutingInstanceDslServiceImpl routingService;

    /**
     * 创建routing实例
     * @param type 类型
     * @param className 类名
     * @param name 名称
     * @param values 数据
     * @return RoutingInstance
     */
    public RoutingInstance add(String type, String className, String name, JSONObject values){
        RoutingInstance instance = routingService.buildNewRoutingInstance(type, className, name, values);
        return routingService.add(instance);
    }

    /**
     * 获取routing实例的json对象
     * @param instance routing实例
     * @return JSONObject
     */
    public JSONObject getRoutingInsJsonObjectList(RoutingInstance instance){
        return routingService.getRoutingInsJsonObjectList(Arrays.asList(instance)).get(0);
    }
}
